$ java · args

Command Line arguments

bash
$ java Greet
Hello
args[0]"Hello"
World
args[1]"World"
3
args[2]"3"
args.length = 3
Note: java and Greet are not in the array — Java's args starts counting from the first word after the class name.
01 · Anatomy

Where args comes from

Every Java program starts at one method, and the JVM hands it exactly one thing: an array of Strings holding whatever you typed after the class name.

public class Greet {
    public static void main(String[] args) {
        // args is created and filled in by the JVM before main() runs
        System.out.println("You passed " + args.length + " argument(s)");
    }
}

Compile and run it, then try passing different numbers of words:

no arguments
$ java Greet
You passed 0 argument(s)
three arguments
$ java Greet Hello World 3
You passed 3 argument(s)

Every element is a String

Even "3" arrives as the two-character string "3", not the number 3. If you need a number, you convert it yourself — the JVM never guesses your intent.